<template>
	<el-form ref="loginForm" :model="form" :rules="rules" label-width="0" size="large" @keyup.enter="login">
		<div class="q-pa-md q-gutter-sm">
			<q-card-section class="q-pt-none">
				{{ ambient }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ user.name }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ url }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ code }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ agentid }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ haha }}
			</q-card-section>
			<q-card-section class="q-pt-none">
				{{ menu }}
			</q-card-section>
		</div>
		<!-- <el-form-item prop="user">
			<el-input v-model="form.user" prefix-icon="el-icon-user" clearable :placeholder="$t('login.userPlaceholder')">
				<template #append>
					<el-select v-model="userType" style="width: 130px;">
						<el-option :label="$t('login.admin')" value="admin"></el-option>
						<el-option :label="$t('login.user')" value="user"></el-option>
					</el-select>
				</template>
			</el-input>
		</el-form-item>
		<el-form-item prop="password">
			<el-input v-model="form.password" prefix-icon="el-icon-lock" clearable show-password
				:placeholder="$t('login.PWPlaceholder')"></el-input>
		</el-form-item>
		<el-form-item style="margin-bottom: 10px;">
			<el-col :span="12">
				<el-checkbox :label="$t('login.rememberMe')" v-model="form.autologin"></el-checkbox>
			</el-col>
			<el-col :span="12" class="login-forgot">
				<router-link to="/reset_password">{{ $t('login.forgetPassword') }}？</router-link>
			</el-col>
		</el-form-item>
		<el-form-item>
			<el-button type="primary" style="width: 100%;" :loading="islogin" round @click="login">{{ $t('login.signIn')
			}}</el-button>
		</el-form-item> -->
		<!-- <div class="login-reg">
			{{ $t('login.noAccount') }} <router-link to="/user_register">{{ $t('login.createAccount') }}</router-link>
		</div> -->
	</el-form>
</template>

<script>

export default {
	data() {
		return {
			userType: 'admin',
			form: {
				user: "admin",
				password: "admin",
				autologin: false
			},
			rules: {
				user: [
					{ required: true, message: this.$t('login.userError'), trigger: 'blur' }
				],
				password: [
					{ required: true, message: this.$t('login.PWError'), trigger: 'blur' }
				]
			},
			islogin: false,
			ambient: '',
			user: {},
			url: '',
			code: '无数据',
			agentid: 0,
			menu: '',
			haha: ''
		}
	},
	watch: {
		userType(val) {
			if (val == 'admin') {
				this.form.user = 'admin'
				this.form.password = 'admin'
			} else if (val == 'user') {
				this.form.user = 'user'
				this.form.password = 'user'
			}
		}
	},
	async created(){
	},
	async mounted() {
		//企业微信 链接写法
		//https://ocr.chem-family.com:1888/scui/?AgentId=1000024#/
		//this.$TOOL.data.clear()
		this.islogin = true
		this.url = window.location.href
		this.ambient = process.env.NODE_ENV
		if (this.ambient === "production") {
			this.code = this.$TOOL.urlExtract(window.location.href, "code");
			this.agentid = this.$TOOL.urlExtract(window.location.href, "AgentId");
			this.menu = this.$TOOL.urlExtract(window.location.href, "menu");
			var e = await this.$API.weixin.GetUserByCode.get(this.code, this.agentid)
			this.haha = e
			this.user = e
			var f = { "userId": "1", "userName": "Administrator", "dashboard": "0", "role": ["SA", "admin", "Auditor"] };
			f.userName = e.name
			f.avatar=e.avatar
			this.$TOOL.data.set("USER_INFO", f)
		} else {
			var d = await this.$API.weixin.GetUserById.get('shaj', '1000029')
			this.user = d
			var b = { "userId": "1", "userName": "Administrator", "dashboard": "0","role": ["SA", "admin", "Auditor"] };
			b.userName = d.name
			b.avatar=d.avatar
			this.$TOOL.data.set("USER_INFO", b)
			this.menu="crm"
		}

		var c = "SCUI.Administrator.Auth";

		this.$TOOL.cookie.set("TOKEN", c, {
			expires: 12 * 60 * 60
		})
		
		this.menu=this.menu+"_menu"
		var a = await await this.$API.menu.GetMenu.get(this.menu)
		console.log(a)
		this.$TOOL.data.set("MENU", a.data.menu)
		this.$TOOL.data.set("PERMISSIONS", a.data.permissions)
		this.$TOOL.data.set("DASHBOARDGRID", a.data.dashboardGrid)

		this.$router.replace({
			path: '/'
		})

		//this.$message.success("Login Success 登录成功")
		this.islogin = false

	},
	methods: {
		async login() {
		},
	}
}
</script>

<style></style>
